package com.lyj.hw_student.system.controller;


import com.lyj.hw_student.common.Result;
import com.lyj.hw_student.system.entity.Course;
import com.lyj.hw_student.system.entity.StudentCourse;
import com.lyj.hw_student.system.entity.SysMenu;
import com.lyj.hw_student.system.service.IStudentCourseService;
import com.lyj.hw_student.system.service.ISysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.web.client.RestTemplateAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.awt.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.List;

import static org.yaml.snakeyaml.tokens.Token.ID.Key;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lyj
 * @since 2025-04-02
 */
@RestController
@RequestMapping("/sysMenu")
public class SysMenuController {
@Autowired
ISysMenuService sysMenuService;


  //查询菜单
    @GetMapping("/getAllMenu")
    public Result<List<SysMenu>> getAllMenu(){
        List<SysMenu> menus = sysMenuService.list();
        return Result.success(menus);
    }
    @GetMapping("/getMenuTree")
    public Result<List<Map<String,Object>>> getMenuTreeByUserId(@RequestParam("userId")String userId){

        return null;
    }

    /**
     * 添加菜单
     * @param sysMenu
     * @return
     */
    @PostMapping("/addMenu")
    public String addMenu(@RequestBody SysMenu sysMenu){
        sysMenuService.save(sysMenu);
        return "addMenu success";
    }

    /**
     * 删除菜单
     * @param menuId
     * @return
     */
    @DeleteMapping("/delMenu/{menuId}")
    public String delMenu(@PathVariable Integer menuId){
        sysMenuService.removeById(menuId);
        return "ok";
    }

    /**
     * 修改菜单
     * @param menu
     * @return
     */
    @PutMapping("/updateMenu")
    public String updateMenu(@RequestBody SysMenu menu) {
        sysMenuService.updateById(menu);
        return "Success";
    }

}
